Back to course home
0% completed
Vote For New Content
Google Hard
Shortest Subarray with Sum at Least K (hard)
Solution: Shortest Subarray with Sum at Least K
Reverse Pairs (hard)
Solution: Reverse Pairs
Nth Magical Number (hard)
Solution: Nth Magical Number
Candy (hard)
Solution: Candy
Arithmetic Slices II - Subsequence (hard)
Solution: Arithmetic Slices II - Subsequence
Burst Balloons (hard)
Solution: Burst Balloons
Sum of Distances in Tree (hard)
Solution: Sum of Distances in Tree
Maximum Score of a Good Subarray (hard)
Solution: Maximum Score of a Good Subarray
Trapping Rain Water (hard)
Solution: Trapping Rain Water
First Missing Positive (hard)
Solution: First Missing Positive
2 Keys Keyboard (medium)
Problem Statement
You're given a notepad that initially displays a single character 'A'. You have two actions available to perform on this notepad for each step:
- Copy All: It allows you to
copy everythingon the screen. - Paste: You can
pastethe characters which arecopiedlast time.
Given an integer n, return the minimum number of operations to print the character 'A' exactly n times on the screen.
Examples
-
Example 1:
- Input:
n = 4 - Expected Output:
4 - Justification: Start with 'A', copy it (
1operation), and paste it(1operations). Now, you have 'AA'. Copy it, and paste it. Total =4operations.
- Input:
-
Example 2:
- Input:
n = 5 - Expected Output:
5 - Justification: Start with 'A', copy it, and paste it four times. Total =
5operations.
- Input:
-
Example 3:
- Input:
n = 9 - Expected Output:
6 - Justification: Start with 'A', copy and paste twice (3 operations) to get 'AAA'. Copy 'AAA' and paste it twice (3 operations) to get 'AAAAAAAAA'. Total =
6operations.
- Input:
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Gray Code
Solution: 2 Keys Keyboard
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself